import pymysql

def main(arg1: str, arg2: str) -> dict:
    results = None  # 初始化results变量
    
    try:
        # 数据库连接配置
        connection = pymysql.connect(
            host='119.23.145.162',  # 数据库服务器地址
            database='erp',  # 数据库名
            user='caerp',      # 用户名
            password='yfskWyXWMKWRwski',  # 密码
            charset='utf8mb4',
            cursorclass=pymysql.cursors.DictCursor
        )
        print("成功连接到 MySQL 服务器")
        
        with connection.cursor() as cursor:
            # 执行查询
            sql = "SELECT * FROM to_sales_order LIMIT 5"
            cursor.execute(sql)
            
            # 获取结果
            results = cursor.fetchall()
            print(f"查询返回了 {len(results)} 条记录")
            
            # 打印结果
            print("\n查询结果:")
            for row in results:
                print(row)
    except Exception as e:
        print(f"数据库错误: {e}")
        return {
            "error": str(e),
            "result": 'query error'
        }
    finally:
        if 'connection' in locals():
            connection.close()
            print("\nMySQL 连接已关闭")
    
    return {
        "result": str(arg1)
    }


if __name__ == "__main__":
    r = main(1, 'select')
    print(r['result'])